package com.Test;

import com.UserServiceImpl.UserService;
import com.javabean.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UTest {
    @Test
    public void test1(){
        ClassPathXmlApplicationContext applicationContext = new
                ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = (UserService) applicationContext.getBean("userService");
        userService.save();
        applicationContext.close();
    }
    @Test
    public void test2() {
        ApplicationContext applicationContext = new
                ClassPathXmlApplicationContext("applicationContext.xml");
        User u1 = (User) applicationContext.getBean("u1");
        System.out.println(u1);
        User u2 = (User) applicationContext.getBean(User.class);

        System.out.println(u2);
        System.out.println(u1.hashCode());
        System.out.println(u1.hashCode());
        System.out.println(u1.equals(u2));
        System.out.println(u1==u2);
    }
    @Test
    public void t3() {
        ClassPathXmlApplicationContext applicationContext = new
                ClassPathXmlApplicationContext("applicationContext.xml");
        User u1 = (User) applicationContext.getBean("u2");
        System.out.println(u1);
        User u2 = (User) applicationContext.getBean("u2");
        System.out.println(u2);
        User u3 = (User) applicationContext.getBean("u2");
        System.out.println(u3);
    }
    @Test
    public void t4() {
        ClassPathXmlApplicationContext applicationContext = new
                ClassPathXmlApplicationContext("applicationContext.xml");
        System.out.println("~~~~~~~~~~~~~~~~~");
        User u4 = (User) applicationContext.getBean("u4");
        u4.setName("u4");
        System.out.println("~~~~~~~~~~~~~~~~~");
        applicationContext.close();
    }
    @Test
    public void t5(){
        ClassPathXmlApplicationContext applicationContext = new
                ClassPathXmlApplicationContext("applicationContext.xml");
        User u3 = (User) applicationContext.getBean("u3");
        u3.setName("被销毁的id为U3的对象");
        applicationContext.close();
    }
}